package com.tvsinfo.jdk.demo.case6_higher_order_function.order;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public enum RefundStatusEnum {

    NO_REFUND(0,1,"no refund","无退款"),   //无退款
    APLLY_REFUND(101,5,"apply refund","申请退款"),     // 申请退款
    REFUSE_REFUND(201,6,"refuse refund","拒绝退款"),     // 拒绝退款

    REFUNING(301,3,"refunding","同意退款"),            // 同意退款，临时状态
    REFUNING_B(301,3,"refunding","退款中"),            // 同意退款，临时状态
    REFUND_FAIL(401,4,"refund fail","退款失败"),       // 退款失败
    REFUND_SUCCESS(501,2,"agree refund","退款成功");   // 退款成功

    private Integer key;
    private Integer oldKey;
    private String desc;
    private String cnDesc;

    RefundStatusEnum(Integer key, Integer oldKey, String desc, String cnDesc){
        this.key = key;
        this.oldKey = oldKey;
        this.desc = desc;
        this.cnDesc = cnDesc;
    }
    private static final Map<Integer, RefundStatusEnum> REFUND_STATUS_ENUM_MAP = new HashMap<>();
    private static final Map<Integer, List<RefundStatusEnum>> OLD_REFUND_STATUS_ENUM_MAP = new HashMap<>();
    static {
        for (RefundStatusEnum _tmp: RefundStatusEnum.values()) {
            REFUND_STATUS_ENUM_MAP.put(_tmp.key, _tmp);

            List<RefundStatusEnum> refundStatusEnums = OLD_REFUND_STATUS_ENUM_MAP.get(_tmp.oldKey);
            if (null == refundStatusEnums) {
                refundStatusEnums = new ArrayList<>();
                OLD_REFUND_STATUS_ENUM_MAP.put(_tmp.oldKey, refundStatusEnums);
            }
            refundStatusEnums.add(_tmp);
        }
    }
    public static List<RefundStatusEnum> getByOldKey(Integer oldKey) {
        if (null == oldKey) {
            return null;
        }
        List<RefundStatusEnum> payStatusEnums = OLD_REFUND_STATUS_ENUM_MAP.get(oldKey);
        return payStatusEnums;
    }


    public static RefundStatusEnum getByKey(Integer key) {
        return REFUND_STATUS_ENUM_MAP.get(key);
    }
    public Integer getKey(){
        return this.key;
    }

    public Integer getOldKey() {
        return oldKey;
    }

    public String getDescription(){
        return this.desc;
    }

    public String getCnDesc() {
        return cnDesc;
    }

    @Override
    public String toString() {
        return "OrdercenterRefundStatusEnum{" +
                "key=" + key +
                ", desc='" + desc + '\'' +
                ", cnDesc='" + cnDesc + '\'' +
                '}';
    }
}
